package com.jingdianjichi.auth.domain.service.impl;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.jingdianjichi.auth.common.enums.IsDeletedFlagEnum;
import com.jingdianjichi.auth.domain.convert.AuthRoleConverter;
import com.jingdianjichi.auth.domain.entity.AuthRoleBO;
import com.jingdianjichi.auth.domain.service.AuthRoleDomainService;
import com.jingdianjichi.auth.infra.basic.entity.AuthRole;
import com.jingdianjichi.auth.infra.basic.service.AuthRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 角色领域
 */
@Service
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {

    @Resource
    private AuthRoleService authRoleService;

    //新增角色
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        AuthRole authRole=AuthRoleConverter.INSTANCE.convertBoToEntity(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());

        Integer count = authRoleService.insert(authRole);

        //关键角色的话是不用和Redis做交互的,用户需要,因为角色的建立没有必要,没有任何关联的东西
        return count>0;
    }

    //修改角色
    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        AuthRole authRole=AuthRoleConverter.INSTANCE.convertBoToEntity(authRoleBO);

        Integer count = authRoleService.update(authRole);
        return count>0;
    }

    //删除角色
    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        AuthRole authRole = new AuthRole();
        authRole.setId(authRoleBO.getId());
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());

        Integer count = authRoleService.update(authRole);

        return count>0;
    }
}
